home *** CD-ROM | disk | FTP | other *** search
- Path: druid.borland.com!usenet
- From: pete@borland.com (Pete Becker)
- Newsgroups: comp.lang.c++
- Subject: Re: pointer questions
- Date: 20 Mar 1996 20:27:37 GMT
- Organization: Borland International
- Message-ID: <4ippnq$irp@druid.borland.com>
- References: <4ifatf$5a8u@uvaix3e1.comp.UVic.CA> <4injoe$qcp@druid.borland.com> <31502C81.1AB6@datalytics.com>
- NNTP-Posting-Host: pbecker.borland.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=ISO-8859-1
- X-Newsreader: WinVN 0.99.5
-
- In article <31502C81.1AB6@datalytics.com>, stew@datalytics.com says...
- >
- >Pete Becker wrote:
- >>
- >> In article <4ifatf$5a8u@uvaix3e1.comp.UVic.CA>, cgesy@uvaix.uvic.ca says...
- >> >
- >> >What does the following statement do/mean? :
- >> >
- >> > ((searchItem&) *this)._refCount++; //searchItem is the class name
- >>
- >> It tells the compiler to pretend that the 'this' pointer actually points to
- an
- >> object of type searchItem, and to increment the member of that object named
- >> _refCount.
- >
- >More to the point, dereferencing this (*this in the example)
- >results in an object of whatever type this points to.
-
- Be a little careful here: *this is not an object, but can be used to access the
- object that 'this' points to.
-
- > That
- >object is then cast to be a reference to class searchItem. This
- >cast is only permissible if this points to a class for which a
- >conversion to searchItem* is available (ARM 5.4).
-
- Yes, but this is a bit misleading, since wild pointer casts are usually
- permitted. In particular, if searchItem has no relationship whatsoever with the
- type that 'this' points to, the cast to searchItem* is legal. Don't make the
- mistake of assuming there is any safety mechanism here. That's why I used the
- word "pretend". If you write code that does this you better be sure you've
- checked all your code paths to guarantee that this cast is safe. The compiler
- will not enforce safety for you here.
- -- Pete
-
-